import os,datetime,json
import traceback

today = datetime.datetime.now().strftime("%Y-%m-%d")
root_path = os.path.split(os.path.realpath(__file__))[0]
log_save_path = root_path + "/logs/"+today+".log"

active = ""
# active = "prod"
# active = "home"
import platform



def get_active_profile():
    if active !="":
        return "-"+active
    return ""

def thirdparty_path():
    if platform.system().lower() == 'windows':
        return os.path.join(root_path,"thirdparty")+"/chromium/win/chrome.exe"
    elif platform.system().lower() == 'linux':
        return os.path.join(root_path,"thirdparty")+"/chromium/linux/chrome"

def load_chrome_userdata():
    return os.path.join(root_path,"thirdparty")+"/userdata"

def load_config():
    config_path = os.path.join(root_path+"/config/config"+get_active_profile()+".json")
    with open(config_path,"r") as f:
        return json.load(f)

def load_mysql_uri():
    config = load_config()
    mysql = config["mysql"]
    mysql_uri = "mysql+pymysql://"+mysql["user"]+":"+mysql["password"]+"@"+mysql["host"]+":"+str(mysql["port"])+"/"+mysql["dbname"]+"?charset="+mysql["charset"]
    return mysql_uri

def load_debug():
    config = load_config()
    if "debug" in config:
        return config["debug"]
    else:
        return False

def load_htmlroot():
    config = load_config()
    return config["htmlroot"]

def load_enable_cache_html():
    config = load_config()
    return config["enable_cache_html"]

def load_temp_save_path():
    config = load_config()
    return config["tmp"]

def load_qcloud():
    config = load_config()
    return config["qcloud"]


if __name__ == '__main__':
    print(load_config())






